package com.cskaoyan._05servlet_configcontext;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @author Macro_Ray
 * @since 2024/5/3 下午5:45
 * ServletRequest 相关方法
 */
@WebServlet("/ss4")
public class ServletRequest1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 行相关
        System.out.println(request.getMethod());  // 获取请求方式
        System.out.println(request.getScheme());  // 获取协议
        System.out.println(request.getProtocol()); // 获取协议和版本号
        System.out.println(request.getRequestURI());  // 获取请求的资源路径
        System.out.println(request.getRequestURL());  // 获取请求的完整URL

        // 头相关 key:value ...
        String accept = request.getHeader("Accept");     // 获取某个请求头的值
        System.out.println("Accept：" + accept);

        Enumeration<String> headerNames = request.getHeaderNames();  // 获取本次请求的所有请求头的名字
        while (headerNames.hasMoreElements()) {
            String s = headerNames.nextElement();
            System.out.println(s+":" +request.getHeader(s));   // 获取 所有请求头的值
        }

        // 获取请求参数


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
